'use strict'
var UserModel = require('../../model/user');
var Data = require('../../util/data')

class Login {
    async post(req, res, next) {
        try {
            const item = req.body
            const phone = item.phone
            const password = item.password
            const user = await UserModel.findOne({ phone });
            if (!user) {
                throw new Error('用户不存在')
            } else if (user.password !== password) {
                throw new Error('密码错误')
            } else {
                res.send(user);
            }
        } catch (err) {
            res.send(Data.throwError(err.message))
        }
    }
}

module.exports = new Login()